Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NT-359] Integrate Updating Backing mutation #893

Merged
merged 9 commits into from
Oct 16, 2019

Conversation

justinswart
Copy link
Contributor

πŸ“² What

A continuation of the work in #887 and #890, this PR is also based off #887's branch.

This wires up the UpdateBacking mutation to allow one to change their payment method and Apple Pay backing.

πŸ€” Why

This is a continuation of the work to allow a user to manage their pledge.

πŸ›  How

  • Added paymentSourceId and ApplePayParams to UpdateBackingData.
  • Created somewhat duplicate signals to handle the result of the apple pay calls. I think when we do the work for the CreateBacking mutation, I may have a way to make this even more reusable due to that mutation and UpdateBacking being so similar.

πŸ‘€ See

Note: Currently the manage pledge view does not refresh automatically, this is a known issue that will be addressed in a subsequent PR. Also, currently the credit card that is the current payment source for the backing is meant to be selected by default and ordered first. This will also be addressed in an upcoming PR. So, at the moment, the experience is that when you land on Change payment method, you may see the incorrect card selected, but the behaviour of the submit button enabling/disabling should still be correct and allow you to change it.

βœ… Acceptance criteria

Be sure to test this against the native dev environment. The payment method that you use and the project that you back should all be created on that environment. Navigate to Change payment method in the Manage pledge view.

  • Select a new payment method and hit confirm you should see a success message and your change reflected (with the caveats mentioned above).
  • Select Apple Pay, the backing should change to an Apple Pay backing*

* I was unable to test this unfortunately as I didn't have an iOS 12 device with me at the time and, although I think it should work, Apple Pay doesn't seem to do anything on the simulator. This is possible a Stripe issue? πŸ€”

// MARK: - Apple Pay
// MARK: - Create Apple Pay Backing

let willCreateApplePayBacking = Signal.combineLatest(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and willUpdateApplePayBacking are to ensure that upon completion of these asynchronous events we show the appropriate messaging/view to the user.


// MARK: - Success/Failure Create

let createPaymentAuthorizationDidFinishSignal = Signal.zip(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zip allows us to ensure that each of these signals will emit at least once before this signal emits. So we know that we started out creating here and not updating because we zip with the willCreateApplePayBacking signal.

@justinswart justinswart mentioned this pull request Oct 12, 2019
3 tasks
@ksr-ci-bot
Copy link

1 Warning
⚠️ Big PR

Generated by 🚫 Danger

Copy link
Contributor

@ifbarrera ifbarrera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial code pass looks good, I'll test this thoroughly tomorrow once we have an Apple Pay sandbox user set up!

Library/ViewModels/PledgeViewModel.swift Outdated Show resolved Hide resolved
let updateBackingDidCompleteApplePay = updateApplePayBackingSuccess
.ignoreValues()
let updateBackingDidComplete = Signal.zip(
self.submitButtonTappedSignal,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, do we need this zip?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm no longer convinced it would do what I need it to here, so I'll consider an alternative.

Library/ViewModels/PledgeViewModelTests.swift Show resolved Hide resolved

let createApplePayBackingData = Signal.combineLatest(
createBackingData,
pkPaymentData.skipNil(),
self.stripeTokenSignal.skipNil()
)
.takeWhen(applePayStatusSuccess)
.takeWhen(willCreateApplePayBacking.filter(isTrue))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might make sense to just put this filter(isTrue) as part of willCreateApplePayBacking.

let updateBackingDataAndIsApplePay = updateBackingData.takePairWhen(
Signal.merge(
updateButtonTapped.mapConst(false),
willUpdateApplePayBacking.filter(isTrue)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here would it make sense to put this filter(isTrue) as part of willUpdateApplePayBacking?

.takeWhen(createApplePayBackingCompleted)
.map(first)

self.confirmationLabelAttributedText = Signal.merge(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this somewhere higher up in the pledge view model? It's kind of separate from the success/failure stuff.

@@ -1256,7 +1258,7 @@ final class PledgeViewModelTests: TestCase {
}
}

func testUpdatingConfirmButtonEnabled_ShippingEnabled() {
func testUpdatingSubmitButtonEnabled_ShippingEnabled() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we change the title of the button? πŸ€”

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's not always a confirm button anymore, sometimes a pledge button. We should also remove the continue button and just use this one.


self.vm.inputs.applePayButtonTapped()

self.notifyDelegateUpdatePledgeDidSucceedWithMessage.assertDidNotEmitValue()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we assert here that the output goToApplePayPaymentAuthorization is called?

self.goToThanks.assertDidNotEmitValue()

self.vm.inputs.applePayButtonTapped()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here can we assert that goToApplePayPaymentAuthorization is called?

self.scheduler.run()

self.notifyDelegateUpdatePledgeDidSucceedWithMessage.assertDidNotEmitValue()
self.updatePledgeFailedWithError.assertValues([
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm so if the request errors before the payment authorization VC has dismissed, the error banner might show below the payment authorization VC πŸ€” that's probably not ideal?

Copy link
Contributor

@ifbarrera ifbarrera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸŽ‰

@justinswart justinswart merged commit e1d63dc into change-payment-method-ui Oct 16, 2019
justinswart added a commit that referenced this pull request Oct 16, 2019
* Updated validation

* Fix snapshot tests, add submitButtonHidden

* Add PledgeAmountSummaryViewController

* Add updateButtonTapped

* Add snapshot test and vm test

* lol

* Remove unused var

* Rename signal, fix payment source ID comparison

* Fix tests

* Fix tests, simplify hiding of shipping location stackview

* Fix snapshots

* Commit the actual snapshots

* Use local var

* [NT-359] Integrate Updating Backing mutation (#893)

* Wire up change payment method to mutation for payment source and Apple Pay

* Remove payment method when backing with Apple Pay and vice versa

* Update tests for apple pay sheet race condition fixes

* Replace zip with simpler signals

* Add Stripe token error test

* Move signals around, improve tests
@justinswart justinswart deleted the change-payment-method-mutation branch July 14, 2021 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants